<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta http-equiv="Content-Type">
		<meta content="text/html; charset=utf-8">
		<meta charset="utf-8">
		<title>报料有奖</title>
		<meta name="description" content="{$_C['site_des']}">
		<meta name="keywords" content="{$_C['site_keyword']}">		
		<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="format-detection" content="email=no">        
		<link rel="stylesheet" type="text/css" href="{$_C.hy_path}css/jp.css" />
	</head>
	<body>
		<div id="content" class="jp-baoliao" style="margin-bottom:40px;">
			<form class="jp-wrap">
					<div class="jp-textarea">
						<p>请填写报料内容或上传照片：</p>
						<textarea placeholder="1-100字以内" name="content"></textarea>
						<img src="{$_C.hy_path}images/p2_textarea.png" class="jp-textarea_bg">
						<img src="{$_C.hy_path}images/p2_camera.png" class="jp-camera send-add">
					</div>
					
					<div class="jp-img">
							
							<img src="{$_C.hy_path}images/add.png" id="add" class="send-add">
					</div>
					
					<div class="jp-input">
						<p>请留下联系电话：</p>
						<input type="text" name="phone">
						<img src="{$_C.hy_path}images/p2_input.png" class="input_bg">
					</div>
					<div class="jp-button">
						<img class="btn submit yf-post" src="{$_C.hy_path}images/p2_btn.png" data-type="yes" />
					</div>
			</form>
			
		</div>
		<p class="foot" >本页面由广州电视台G4提供</p> 
			
		<div class="alert" id="alert2" style="padding:15px">
		
			<div id="msg" class="fs3"></div>
			
			
			<a href="javascript:void(0)" class="alert-btn fc1 fs3">确定</a>
			
		</div>
		<script type="text/javascript" src="{$_C.hy_path}js/zepto.min.js"></script>
		<script type="text/javascript" src="{$_C.hy_path}js/main.js"></script>
		<script src="{$_C.hy_path}js/yf.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
		<script>
			
		
	
		
			var num = 0;
	
		
				function showMsg(msg)
			{
					$("#msg").text(msg);
					$('div#alert2').show();
			}
	
			$(function(){
				
					
				$('a.alert-btn').click(function (e) {
					$('div.alert').hide();
					});
					
	
	
				$('.yf-post').click(function(){
					
					var _this = $(this);
					var type = _this.attr('data-type');
					if(type == 'done')
					{
						showMsg("你今天已报过料了");
					}
					else if(type == 'yes')
					{
						var data = {};
						var data_arr = $('form').serialize().replace(/\+/g,' ').split('&');
						for(var i=0;i<data_arr.length;i++)
						{
							var temp=data_arr[i].split('=');
							if(typeof(data[hungry.util.utf8_decode(temp[0])])!='undefined')
							{
								var arr=[];
								if(data[hungry.util.utf8_decode(temp[0])] instanceof Array)
								{
									arr=data[hungry.util.utf8_decode(temp[0])];
								}
								else
								{
									arr.push(data[hungry.util.utf8_decode(temp[0])]);
								}
									arr.push(hungry.util.utf8_decode(temp[1]));
									data[hungry.util.utf8_decode(temp[0])]=arr;
							}
							else
							{
								data[hungry.util.utf8_decode(temp[0])]=hungry.util.utf8_decode(temp[1]);
							}
						}
						_this.attr('data-type', 'no');
						_this.text('提交中');
						$.post('index.php?g=mobile&m=suipai&a=send_set',data,function(result){
							if(result.error == 0)
							{
								showMsg(result.content);
								_this.attr('data-type', 'done');
								setTimeout("location.reload()",3000);
								//location.reload();
							}
							else
							{
								
								showMsg(result.content);
								_this.attr('data-type', 'yes');
								_this.text('提交');
							}
						},'json');
					}
					else
					{
						showMsg("数据提交中");
					}
				});
			});
			
			wx.config({
				debug: false,
				appId: '{$jsdk.appId}',
				timestamp: {$jsdk.timestamp},
				nonceStr: '{$jsdk.nonceStr}',
				signature: '{$jsdk.signature}',
				jsApiList: [
					'chooseImage',
					'previewImage',
					'uploadImage',
					'downloadImage',
					 'onMenuShareTimeline',
		      'onMenuShareAppMessage'
				]
			});
			
			var images = {
				    localId: [],
				    serverId: []
				  };
			
			var urls = {
				   current: '', // 当前显示图片的http链接
    urls: [] // 需要预览的图片http链接列表
				  };
				  
			wx.ready(function(){
				
				
				
				
				 wx.onMenuShareTimeline({
    
    title: '报料有奖',
   // desc: '一经采纳，即有大奖！',
  imgUrl: 'http://yf.lly360.com/Mobile/Webroot/gf/images/share-suipai3.png',
  
      trigger: function (res) {
       
      },
      success: function (res) {
       			
			
      },
      cancel: function (res) {
       
      },
      fail: function (res) {
        alert(JSON.stringify(res));
      }
    });
    
	wx.onMenuShareAppMessage({
   // link:'http://wxyx.weidianit.com/index.php?g=home&m=shake&a=index&pid='+pid,
     title: '报料有奖',
    desc: '一经采纳，即有大奖！',
  imgUrl: 'http://yf.lly360.com/Mobile/Webroot/gf/images/share-suipai3.png',
    success: function () { 
	
				
    },
    cancel: function () { 
        // 用户取消分享后执行的回调函数
    }
});
				
				
				
				
				$('.send-add').click(function(){
					
					
					
					if(num>=9)
					{
						showMsg("至多可上传9张图片");
						return;
					}
					wx.chooseImage({
						success: function (res) {
					        images.localId = res.localIds;
					        //showMsg('已选择 ' + res.localIds.length + ' 张图片');
					        if (images.localId.length == 0) {
					  	      	showMsg('请先选择图片');
								return;
					  	    }
					        
					        var i = 0; 
					        var length = images.localId.length;
					        images.serverId = [];
					        function upload() 
					        {
								
								if(num>=9)
								{
									
									return;
								}
								
								var img;
								
					        	wx.uploadImage({
					        		localId: images.localId[i],
					      		    success: function (res) {
					      		    	i++;
					      		    	num++;
					      		    	images.serverId.push(res.serverId);
					      		    	img = res.serverId;
					      		    	$.post('index.php?g=mobile&m=suipai&a=upload_img',{ img:img },function(result){
					      		    		if(result.error == 0)
					      		    		{
												$(result.url).insertBefore("#add");
					      		    		
												$(result.content).appendTo('.jp-textarea');
												if(i==1)
												{
													
													urls.current = result.img;
													
												}
												urls.urls[i-1] = result.img;
												
					      		    			if(i < length) 
							      	          	{
							      	            	upload();
							      	          	}
					      		    			if(i == length)
					      		    			{
													if(num>=9)
													{
														$("#add").hide();
														
													}
					      		    				showMsg("全部上传成功");
													
													$(".pre-img").click(function(){
													wx.previewImage(urls);
												});
												
//													wx.downloadImage({
//    serverId: img, // 需要下载的图片的服务器端ID，由uploadImage接口获得
//    isShowProgressTips: 1, // 默认为1，显示进度提示
//    success: function (res) {
//alert(111);
//        var localId = res.localId; // 返回图片下载后的本地ID
//   
//    }
//});
													
					      		    			}
					      		    		}
					      		    		else
					      		    		{
					      		    			showMsg('上传失败');
					      		    			return;
					      		    		}
					      		    	},'json');
					      		    }
					        	});
					        }
					        
					        upload();
					    }
					});
				});
			});
			
			
			
		</script>
	</body>
</html>
